//
//  YIem_Find_Topics_ViewController.m
//  B段_开眼
//
//  Created by YIem on 16/4/28.
//  Copyright © 2016年 Howie. All rights reserved.
//

#import "YIem_Find_Topics_ViewController.h"

@interface YIem_Find_Topics_ViewController ()<UITableViewDataSource, UITableViewDelegate >
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation YIem_Find_Topics_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataArr = [NSMutableArray array];
    self.navigationItem.title = @"专题";
    self.view.backgroundColor = [UIColor whiteColor];
    // 返回
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_back_normal"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:0.2077 green:0.2077 blue:0.2077 alpha:1.0];
    

   
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    //    self.tableView.backgroundCorlor = [UIColor greenColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[YIem_Find_Topics_TableViewCell class] forCellReuseIdentifier:@"YIem_Find_Topics_TableViewCell"];
    

    // 解析
    [self dataBase];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YIem_Find_Topics_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YIem_Find_Topics_TableViewCell" forIndexPath:indexPath];
    
    cell.model = self.dataArr[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return hEIGHT;
  
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YIem_Find_Topics_DetailViewController *detail = [[YIem_Find_Topics_DetailViewController alloc] init];
    detail.strUrl = [self.dataArr[indexPath.row]actionUrl];
    
    [self.navigationController pushViewController:detail animated:YES];
}


// 解析
- (void)dataBase
{
    NSString *url = @"http://baobab.wandoujia.com/api/v3/specialTopics?&num=20";

    [YIem_Find_Topics_VIewModel getDataWithPage:url andUpdate:YES andBlock:^(NSMutableArray *arr) {
        self.dataArr = arr;
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
        
    }];
    
}

- (void)leftAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
